package com.tanhua.server.contoller;

import com.tan.model.dto.RecommendUserDto;
import com.tan.model.mongo.RecommendUser;
import com.tan.model.vo.NearUserVo;
import com.tan.model.vo.PageResult;
import com.tan.model.vo.TodayBest;
import com.tanhua.dubbo.api.RecommendUserApi;
import com.tanhua.server.interceptor.Userthread;
import com.tanhua.server.service.TanhuaService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class tanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
      Long id=  Userthread.getUser().getId();
     TodayBest todayBest =  tanhuaService.queryWithtodaybest(id);


        return ResponseEntity.ok(todayBest);
    }
    /**
     * 查询分页推荐好友列表
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        PageResult pr = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pr);
    }
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity getUserInfo(@PathVariable("id") Long id) {
        TodayBest todayBest = tanhuaService.queryWithmyliketodaybest(id);
        return ResponseEntity.ok(todayBest);
    }
    @GetMapping("/strangerQuestions")
    public ResponseEntity getStrangerQuestions(Long userId) {
        String question = tanhuaService.getStrangerQuestions(userId);
        return ResponseEntity.ok(question);
    }
    @PostMapping("/strangerQuestions")
    public ResponseEntity answerStrangerQuestions(@RequestBody Map map) {
       Integer userId = (Integer) map.get("userId");
       String reply = (String) map.get("reply");
        tanhuaService.answerStrangerQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }
    /**
     * 探花-推荐用户列表
     */
    @GetMapping("/cards")
    public ResponseEntity queryCardsList() {
        List<TodayBest> list = this.tanhuaService.queryCardsList();
        return ResponseEntity.ok(list);
    }
    /**
     * 喜欢
     */
    @GetMapping("{id}/love")
    public ResponseEntity<Void> likeUser(@PathVariable("id") Long likeUserId) {
        this.tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLikeUser(@PathVariable("id") Long likeUserId) {
        this.tanhuaService.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/search")
    public ResponseEntity searchUser(String gender,@RequestParam(defaultValue = "2000")String distance) {
        List<NearUserVo> nearUsers = tanhuaService.searchUser(gender,distance);
        return ResponseEntity.ok(nearUsers);
    }


}
